<template>
    <div>
        <el-form style="width:75vw" label-position="right" label-width="80px" :model="data" ref="application_ref"
            :rules="rules">
            <el-form-item label="姓名" prop="username">
                <el-input v-model="data.username" disabled></el-input>
            </el-form-item>
            <el-form-item label="手机号" prop="phone">
                <el-input v-model="data.phone"></el-input>
            </el-form-item>
            <el-form-item label="学历">
                <el-select v-model="data.academic_degree" placeholder="点击选择">
                    <el-option v-for="item in academic_degree" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="毕业院校" prop="school">
                <el-input v-model="data.school"></el-input>
            </el-form-item>
            <el-form-item label="专业" prop="speciality">
                <el-input v-model="data.speciality"></el-input>
            </el-form-item>
            <el-form-item label="导游证号" prop="information">
                <el-input v-model="data.information"></el-input>
            </el-form-item>
            <el-form-item label="旅行社">
                <el-select v-model="data.enterprise_id" placeholder="请选择意向">
                    <el-option v-for="item in enterprise_options" :key="item.name" :label="item.name" :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="工作经历" prop="content">
                <el-input type="textarea" :rows="6" v-model="data.content"></el-input>
            </el-form-item>

        </el-form>
        <div class="btn">
            <el-button type="primary" class="next_btn" size="medium" @click="() => $emit('pre_step', true)">
                <i class="el-icon-back"></i> 上一步
            </el-button>
            <el-button type="primary" class="next_btn" style="margin-left:20px ;" size="medium" @click="submit_application">
                提交 <i class="el-icon-right"></i>
            </el-button>
        </div>
    </div>
</template>

<script>
import { rules } from '@/utils/rules'
export default {
    data() {
        return {
            data: {
                user_id: sessionStorage.user_id,
                username: '',
                phone: '',
                enterprise_id: 0,
                content: '',
                information: '',
                academic_degree: '',
                school: '',
                speciality: '',
            },
            enterprise_options: [],
            academic_degree: [
                { id: 0, name: '博士研究生' },
                { id: 1, name: '硕士研究生' },
                { id: 2, name: '大学本科' },
                { id: 3, name: '大学专科' },
                { id: 4, name: '普通高中' },
                { id: 5, name: '职业高中' },
            ],
            rules: null,
        }
    },

    mounted() {
        this.rules = rules
        this.get_all_agency()
        this.username = sessionStorage.username
    },

    methods: {
        async get_all_agency() {
            try {
                const res = await this.$http.get("/findAllAgency");
                // console.log(res)
                this.enterprise_options = res.data.data
            } catch (error) { }
        },

        // application_ref
        async submit_application() {
            const res = await this.$http.post("/addApplication", {
                user_id: sessionStorage.user_id,
                content: this.data.content,
                agency_id: this.data.enterprise_id,
                information: this.data.information,
                academic_degree: this.data.academic_degree,
                speciality: this.data.speciality,
                school: this.data.school,
            });
            console.log(this.data)

            if (res.data.code === 2000 && res.data.data === 1) {
                this.$message.success('成功')
                this.$emit('next_step', true)
            } else {
                this.$message.success('失败')
            }
        }
    }
}
</script>

<style lang="less" scoped>
.btn {
    position: absolute;
    left: 50%;
    transform: translate(-50%, 30%);
}

.next_btn {
    margin: 0 auto;
    height: 40px
}
</style>